//
//  StockKlineMANumberView.m
//  K线图自治
//
//  Created by LK-IOS on 2017/12/15.
//  Copyright © 2017年 LK-IOS. All rights reserved.
//



#import "StockKlineMANumberView.h"
#import "StockKLineUntil.h"
#import "UIColor+StockColorEntension.h"

@interface StockKlineMANumberView()

@property (nonatomic , strong) UILabel *maLabel;

@end

@implementation StockKlineMANumberView

-(instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self maLabel];
    }
    return self;
}

-(UILabel *)maLabel
{
    if (!_maLabel)
    {
        _maLabel = [[UILabel alloc] init];
        [self addSubview:_maLabel];
        _maLabel.font = [UIFont systemFontOfSize:font10ScreenWRate * LKScreenW];
        _maLabel.textAlignment = NSTextAlignmentLeft;
        _maLabel.backgroundColor = [UIColor whiteColor];
        _maLabel.textColor = [UIColor Stock_TextColor];
        [_maLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.bottom.top.equalTo(self);
        }];
        _maLabel.text = @"日K  MA5:--  MA10:--  MA20:--";
        _maLabel.adjustsFontSizeToFitWidth = YES;
    }
    return _maLabel;
}

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];

    if (!self.malinesArray.count)return;
    StockKLineUntil *ma5Until = self.malinesArray.firstObject;
    StockKLineUntil *ma10Until = self.malinesArray[1];
    StockKLineUntil *ma25Until = self.malinesArray[2];

    NSString *ma5Number = [NSString stringWithFormat:@"%.2f" ,ma5Until.value];
    NSString *ma5String = [NSString stringWithFormat:@"MA5:%@" , ma5Number];

    NSString *ma10Number = [NSString stringWithFormat:@"%.2f" ,ma10Until.value];
    NSString *ma10String = [NSString stringWithFormat:@"MA10:%@" , ma10Number];

    NSString *ma25Number = [NSString stringWithFormat:@"%.2f" ,ma25Until.value];
    NSString *ma25String = [NSString stringWithFormat:@"MA25:%@" , ma25Number];


    NSString *maString = [NSString stringWithFormat:@"K线  %@  %@  %@" , ma5String , ma10String , ma25String];


    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:maString];

    [attStr addAttribute:NSForegroundColorAttributeName
                   value:[UIColor Stock_MA5Color]
                   range:[maString rangeOfString:ma5String]];

    [attStr addAttribute:NSForegroundColorAttributeName
                   value:[UIColor Stock_MA10Color]
                   range:[maString rangeOfString:ma10String]];


    [attStr addAttribute:NSForegroundColorAttributeName
                   value:[UIColor Stock_MA25Color]
                   range:[maString rangeOfString:ma25String]];
    
    _maLabel.attributedText = attStr;

}


@end
